package org.wu.framework.web.spring.ui.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.GetMapping;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import org.wu.framework.web.spring.EasyController;
import org.wu.framework.web.ui.LazyUI;

import java.util.List;
import java.util.stream.Collectors;

@EasyController("/ui/v1/api/ui")
public class UIController {

    private final List<LazyUI> lazyUIList;

    public UIController(List<LazyUI> lazyUIList) {
        this.lazyUIList = lazyUIList;
    }

    /**
     * 获取所有的 UI地址
     * @return
     */
    @Operation(summary = "获取所有的 UI地址")
    @GetMapping("/findUI")
    public Result<List<WebLazyUI>> findUI(){
        return ResultFactory.successOf(lazyUIList.stream().filter(LazyUI::support).map(lazyUI -> {
            WebLazyUI webLazyUI = new WebLazyUI();
            webLazyUI.setDesc(lazyUI.desc());
            webLazyUI.setIndex(lazyUI.index());
            webLazyUI.setLocations(lazyUI.locations());
            webLazyUI.setPathPatterns(lazyUI.pathPatterns());
            return webLazyUI;
        }).collect(Collectors.toList()));
    }



}
